/*
 * Copyright (c) 2013-2018 上海汇数数据. All rights reserved.
 * @(#) ErrorChinaID.java 2018-08-05 23:25
 */

package cn.jh.common.core.id;


import cn.jh.common.core.domain.Gender;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import org.joda.time.LocalDate;

import java.util.Objects;


/**
 * 身份证号码解析错误（不合法）时，返回的对象模型。
 *
 * @author Fuchun
 * @since 1.0
 */
final class ErrorChinaID extends ChinaID {

    private static final long serialVersionUID = 1L;

    private final String number;

    ErrorChinaID(String number) {
        this.number = number;
    }

    @Contract(pure = true)
    @Override
    public String getNumber() {
        return number;
    }

    @Contract(pure = true)
    @Override
    public int getValidLength() {
        return -1;
    }

    @Contract(pure = true)
    @Override
    public boolean isValid() {
        return false;
    }

    @Nullable
    @Contract(pure = true)
    @Override
    public String getStateCode() {
        return null;
    }

    @Nullable
    @Contract(pure = true)
    @Override
    public String getAreaCode() {
        return null;
    }

    @Contract(pure = true)
    @Override
    public Gender getGender() {
        return Gender.UNKNOWN;
    }

    @Nullable
    @Contract(pure = true)
    @Override
    public LocalDate getBirthday() {
        return null;
    }

    @Contract(pure = true)
    @Override
    public int getAge() {
        return -1;
    }

    @Contract(value = "null -> false", pure = true)
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ErrorChinaID)) return false;
        ErrorChinaID that = (ErrorChinaID) o;
        return Objects.equals(number, that.number);
    }

    @Override
    public int hashCode() {
        return Objects.hash(number);
    }

    @Override
    public String toString() {
        return String.format("ErrorChinaID{id=%s}", getNumber());
    }
}
